package com.ibeeking.found.open.b.rest.service.impl;

import com.ibeeking.found.open.api.common.dto.ShopDTO;
import com.ibeeking.found.open.api.feign.SystemFeignClient;
import com.ibeeking.found.open.b.rest.service.ISystemService;
import com.ibeeking.nematos.exception.BusinessException;
import com.ibeeking.nematos.exception.DataNotExistException;
import com.ibeeking.nematos.utils.data.StringUtils;
import com.ibeeking.nematos.utils.result.ResponseResult;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @ClassName SystemServiceImpl
 * @Description
 * @Author ibeeking
 * @Date 2021-06-15 10:08
 **/
@Service
public class SystemServiceImpl implements ISystemService {

    @Resource
    private SystemFeignClient systemFeignClient;

    @Override
    public Long queryShopIdByShopCode(String shopCode) {
        if (StringUtils.isBlank(shopCode)) {
            throw new BusinessException("商户编码不能为空");
        }
        ResponseResult<ShopDTO> responseResult = systemFeignClient.queryByShopCode(shopCode);
        if (null == responseResult || null == responseResult.getData()) {
            throw new DataNotExistException("商户不存在");
        }
        return responseResult.getData().getId();
    }
}
